<template>
	<view class="page" :style="{minHeight:$height()}">
		<view class="title" style="margin-bottom: 16rpx;">
			信息确认
		</view>

		<view class="item" style="margin-bottom: 16rpx;">
			<view class="left">
				<text class="info">
					姓名
				</text>
				<text class="xing">*</text>
			</view>
			<view class="right">
				<u-input v-model="form.userName" :placeholder="`请输入姓名`" />
			</view>
		</view>
		<view class="item">
			<view class="left">
				<text class="info">
					电话
				</text>
				<text class="xing">*</text>
			</view>
			<view class="right">
				<u-input disabled v-model="form.phone" type="numbel" placeholder="请授权获取手机" />
				<button class="send" lang="zh_CN" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">
					点击授权
				</button>
			</view>
		</view>
		<view class="item">
			<view class="left">
				<text class="info">绿证数量</text>
				<text class="xing">*</text>
			</view>
			<view class="right">
				<u-input v-model="form.greenCardNum" :type="number" placeholder="请输入所需绿证数量" />
			</view>
		</view>
		<view class="item" style="margin-bottom: 16rpx;">
			<view class="left">
				<text class="info">
					企业名称
				</text>
				<!-- <text class="xing">*</text> -->
			</view>
			<view class="right">
				<u-input v-model="form.companyName" :placeholder="`请输入企业名称`" />
			</view>
		</view>

		<view class="item">
			<view class="left">
				<text class="info">地址</text>
				<!-- <text class="xing">*</text> -->
			</view>
			<view class="right">
				<u-input v-model="form.address" type="text" placeholder="请输入地址" />
			</view>
		</view>
		<view class="item">
			<view class="left">
				<text class="info">绿证</text>
				<!-- <text class="xing">*</text> -->
			</view>
			<view class="right">
				<u-checkbox-group @change="checkboxGroupChange">
					<u-checkbox v-model="item.checked" v-for="(item, index) in greenCardTypelist" :key="index"
						:name="item.name">{{item.title}}</u-checkbox>
				</u-checkbox-group>
			</view>
		</view>

		<view class="footer">
			<view class="compelet" @click="submit">
				提交申请
			</view>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				form: {
					userName: '',
					phone: '',
					companyName: '',
					address: '',
					greenCardType: null,
					greenCardNum: 1,
					code:null,
				},
				greenCardTypelist: [{
						name: '0',
						title:'国内',
						checked: false,
						disabled: false
					},
					{
						name: '1',
						title:'国际',
						checked: false,
						disabled: false
					}
				],
				userinfo: uni.getStorageSync("userinfo"),
				heHuoShengFenData: [],
			}
		},
		onShow() {
			this.form.phone = this.userinfo.mobile
			this.getHeHuoRen()
		},

		onLoad() {},
		methods: {
			// 合伙人省份查询
			getHeHuoRen() {
				this.$axios.request(this.$api.ShiListApi, "GET", {
					pid: 0,
					hasTowner: 1
				}).then((val) => {
					this.heHuoShengFenData = val.data.map(items => {
						return {
							id: items.id,
							name: items.name
						}
					})
				})
			},
			// 选择地区 end
			decryptPhoneNumber(e) {
				if (!e.target.iv) {
					uni.showModal({
						content: '获取手机号失败！',
						showCancel: false
					})
					return;
				}

				this.$wechat.getcode().then((code) => {
					this.$axios.request(this.$api.getUserMobile, "GET", {
						code: code.code,
						encryptedData: e.detail.encryptedData,
						ivStr: e.detail.iv
					}).then((val) => {
						if (val.code == 0) {
							this.form.phone = val.data.mobile
						} else {
							this.$msg.toast("获取手机号码失败")
						}

					})
				})
			},
			checkboxGroupChange(e) {
				console.log(e);
				this.form.greenCardType = e.join(',')
			},
			submit() {
				if (this.form.userName == '') {
					return this.$msg.toast("请输入姓名")
				}
				if (!this.form.phone) {
					return this.$msg.toast("请授权手机号")
				}
				if (this.form.greenCardNum == '') {
					return this.$msg.toast("请输入绿证数量")
				}
				let reg = /^[0-9]*$/
				if(!reg.test(this.form.greenCardNum)) {
					return this.$msg.toast("请输入数字类型的绿证数量")
				}
				// 获取code
				this.$wechat.getcode().then(code => {
					this.form.code = code.code
					this.$axios.request(this.$api.lvDianLvzhengLvShouForm, "POST", this.form).then((val) => {
						this.$msg.toast("提交成功")
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/index/index'
							})
						},1000)
					})
				})
				
		
			},

		}
	}
</script>

<style>
	.page {
		width: 100%;
		overflow: hidden;
		background-color: #F9F9FB;
	}

	.title {
		width: 686;
		height: 80rpx;
		padding: 0 32rpx;
		background-color: #FFFFFF;
		margin: 16rpx auto 0;
		font-size: 32rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		line-height: 80rpx;
		color: #333333;
		opacity: 1;
	}

	.item {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		width: 100%;
		height: 90rpx;
		padding: 0 32rpx 0;
		background-color: #FFFFFF;
		margin-bottom: 8rpx;
		margin-bottom: 16rpx;
	}

	.itembie {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: flex-start;
		width: 100%;
		/* height: 90rpx; */
		padding: 10rpx 32rpx 24rpx;
		background-color: #FFFFFF;
		margin-bottom: 8rpx;
		margin-bottom: 16rpx;
	}

	.left {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		width: 260rpx;
		height: 64rpx;
	}

	.info,
	.xing {
		height: 80rpx;
		line-height: 80rpx;
		font-size: 30rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		color: #333333;
		opacity: 1;
	}

	.xing {
		color: #FF2D55;
		font-size: 30;
		height: 64rpx;
		line-height: 64rpx;
		margin-left: 10rpx;
		padding-top: 7rpx;
	}

	.right {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 30rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		color: #62656D;
		opacity: 1;
	}

	.compelet {
		width: 686rpx;
		height: 80rpx;
		background-color: #2E6ADF;
		opacity: 1;
		border-radius: 4rpx;
		font-size: 32rpx;
		font-family: "PingFang SC";
		font-weight: 400;
		line-height: 80rpx;
		margin: 0 auto 0;
		text-align: center;
		color: #FFFFFF;
		opacity: 1;
	}

	.biTian {
		height: 80rpx;
		line-height: 80rpx;
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		color: #62656D;
		margin-left: 20rpx;
	}

	.idBox {
		overflow: hidden;
		height: 448rpx;
		background-color: #FFFFFF;
		margin: 16rpx 0;
	}

	.idTitle {
		height: 28rpx;
		font-size: 26rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		line-height: 28rpx;
		color: #FF2D55;
		opacity: 1;
		margin: 32rpx 32rpx 64rpx;
	}

	.idImageBox {
		width: 288rpx;
		height: 250rpx;
	}

	.imageTxt {
		height: 33rpx;
		font-size: 24rpx;
		font-family: "PingFang SC";
		font-weight: 400;
		line-height: 33rpx;
		color: #707070;
		opacity: 1;
		margin-top: 20rpx;
	}

	.footer {
		display: flex;
		align-items: center;
		overflow: hidden;
		width: 100%;
		height: 227rpx;
		background-color: #FFFFFF;
		margin-top: 16rpx;
	}

	.send {
		height: 40rpx;
		font-size: 24rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		line-height: 40rpx;
		color: #2E6ADF;
		opacity: 1;
		border: 1rpx solid #2E6ADF;
		padding: 0 8rpx;
	}

	.checkBoxRow {
		/* width: 200rpx; */
		display: inline-block;
		/* background-color: #2E6ADF; */
		/* margin-right: 60rpx;
		 */
		/* margin: 30rpx; */
	}

	.right1 {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		/* background-color: red; */
	}
</style>